<?php
/**
 * 好友验证接口
 *
 */
class friends_util_checker
{
	const ERROR_ONLYFRIEND = 'err_onlyfriend';
	
	/**
	 * 是否是好友的好友
	 *
	 * @param int $host_id
	 * @param int $uid
	 * @return int
	 */
	public static function isFriendOfMyFriend($host_id, $uid)
	{
		$host_id = (int) $host_id;
		$uid 	 = (int) $uid;
		if (!$host_id || !$uid) return false;
		
		return Model::factory('friends_model_data')->isFriendOfMyFriend($host_id, $uid);
	}
	
	/**
	 * 是否是好友
	 *
	 * @param int $aid
	 * @param int $bid
	 * @return unknown
	 */
	public static function isFriend($aid, $bid)
	{
		$aid = (int) $aid;
		$bid = (int) $bid;
		if (!$aid || !$bid) return false;
		
		$friends = friends_util_friendutil::getFriendIds($aid);
		return in_array($bid, $friends);
		
		//return Model::factory('friends_model_data')->isFriend($aid, $bid);
	}
	
	/**
	 * 两个用户共同的好友
	 *
	 * @param int $uid1
	 * @param int $uid2
	 * @return array
	 */
	public static function commFriends($uid1, $uid2)
	{
		$uid1 = (int) $uid1;
		$uid2 = (int) $uid2;
		if (!$uid1 || !$uid2) return array();
		
		return Model::factory('friends_model_data')->commFriends($uid1, $uid2);
	}
	
	/**
	 * 是否已经发送了好友请求
	 *
	 * @param int $host_id
	 * @param int $uid
	 * @return bool
	 */
	public static function isSendFriend($host_id, $uid)
	{
		$host_id = (int) $host_id;
		$uid 	 = (int) $uid;
		if (!$host_id || !$uid) return false;
		
		return Model::factory('friends_model_data')->isRequest($host_id, $uid);
	}
	
	/**
	 * 加好友任务接口
	 *
	 * @param int $uid
	 * @param int $time
	 * @return int
	 */
	public static function questCheck($uid, $time)
	{
		return Model::factory('friends_model_data')->questCheck($uid, $time);
	}
	
	public static function invitationQuestCheck($uid, $time)
	{
		return Model::factory('friends_model_invitation')->checkQuest($uid, $time);
	}	
}
